package com.cloudptt.api.product.func.call.single;

import java.io.File;
import java.util.List;
import java.util.Vector;

import com.cloudptt.api.comm.CauseCont;
import com.cloudptt.api.comm.CommDlg;
import com.cloudptt.api.comm.Common;
import com.cloudptt.api.pjsip.api.SipManager;
import com.cloudptt.api.product.func.call.CallAttr;
import com.cloudptt.api.product.func.call.CallConst;
import com.cloudptt.api.product.func.call.CallListener;
import com.cloudptt.api.product.func.call.CallTimer;
import com.cloudptt.api.product.func.call.group.HalfCallInfo;
import com.cloudptt.api.product.func.call.group.fsm.call.GroupCallAgent;
import com.cloudptt.api.product.func.call.group.fsm.video.trans.VideoTransAgent;
import com.cloudptt.api.product.func.call.single.fsm.ActiviteState;
import com.cloudptt.api.product.func.call.single.fsm.ConnectingState;
import com.cloudptt.api.product.func.call.single.fsm.DisconnectingState;
import com.cloudptt.api.product.func.call.single.fsm.ICallState;
import com.cloudptt.api.product.func.call.single.fsm.InitialState;
import com.cloudptt.api.product.func.call.single.fsm.WattingState;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.api.product.operator.CallOperator;
import com.cloudptt.api.product.res.Resource;
import com.mcptt.config.model.McIdInfo;
import com.mcptt.db.model.AddrInfo;

import android.content.Context;
import android.content.Intent;
import android.os.Environment;


public class SingleCallAgent implements ICallState
{
	public final static String Log_Key = "SingleCallTracker";

	private static final int Timer_Private = 24;
	private static final int Timer_Other = 6;

	private ICallState currentState = null;
	private int callMediaState = CallConst.CallMediaState_None;
	private Class<?> activityCls = null;
	private Class<?> floatWindowServiceCls = null;
	private CallListener listener = null;

	private Context ctx = null;
	private CallAttr callAttr = null;
	private CallOperator operator = null;
	private CallTimer callTime = null;
	private IClearCall clearCall = null;

	private String curCallIdStr = CallAttr.DEF_CALL_ID_STR;
	private String callkey = null;
	private String timeDesc = null;
	private boolean islaunch = true;
//	private AlarmTimer keepLiveTimer = null;
//	private volatile boolean isStartTimer = false;
	public final static String TimerOutKey_Negotiate= "negotiate";
	private boolean haseVideo = false;
	private boolean isShowFloatWin = false;




	public SingleCallAgent(Context ctx,CallAttr callAttr,McIdInfo mcIdInfo,CallOperator operator,IClearCall clearCall)
	{
		Log.debug(this.getClass(), "CallAgent callAttr = " + callAttr);
		this.ctx = ctx;
		this.callAttr = callAttr;
		this.callkey = callAttr.getCallKey();
		this.curCallIdStr = callAttr.getCallIdStr();
		this.currentState = new InitialState(this);
		this.operator = operator;

		this.callTime = CallTimer.getDefaultCallTimer();
		this.clearCall = clearCall;
//		this.isRefreshVideo = false;
		//		this.localRender = new SurfaceViewRenderer(ctx);
		//		this.remoteRender = new SurfaceViewRenderer(ctx);
	}

	public void updateCallIdStr(String callIdStr)
	{
		Log.debug(this.getClass(), "updateCallIdStr callIdStr = " + callIdStr);
		this.curCallIdStr = callIdStr;
		if(callAttr != null) {
			this.callAttr.updateCallIdStr(callIdStr);
		}
		if(listener != null)
		{
			listener.updateCallState(callkey,currentState.getState(),haseVideo);
		}
	}
	public void setPrivacyClass(Class activityCls,Class floatWindowServiceCls)
	{
		this.activityCls = activityCls;
		this.floatWindowServiceCls = floatWindowServiceCls;
	}

	//	public SurfaceViewRenderer getSurfaceView(int type)
	//	{
	//		if(CallConst.SurfaceView_Type_Local == type)
	//		{
	//			return localRender;
	//		}
	//		else if(CallConst.SurfaceView_Type_Remote == type)
	//		{
	//			return remoteRender;
	//		}
	//		return null;
	//	}

	public void setIslaunch(boolean islaunch)
	{
		Log.debug(this.getClass(), "setIslaunch islaunch = " + islaunch);
		this.islaunch = islaunch;
	}

	public void goToState(int nextState){
		ICallState callState = null;
		Log.debug(this.getClass(), "goToState:["+ CallConst.stateTag(this.currentState.getState()) +
				" to "+ CallConst.stateTag(nextState) + "]");

		switch (nextState) {
			case CallConst.CallState_InitState:
				callState = new InitialState(this);
				break;
			case CallConst.CallState_WattingState:
				int seconds = getMakeCallTimer();
				int callDir = callAttr.getCallDir();
				callState = new WattingState(ctx,this,seconds,callDir);
				break;
			case CallConst.CallState_ConnectingState:
				seconds = getMakeCallTimer();
				callDir = callAttr.getCallDir();
				callState = new ConnectingState(ctx,this,seconds,callDir);
				break;
			case CallConst.CallState_Activite:
				callState = new ActiviteState(this);
				break;
			case CallConst.CallState_DisconnectingState:
				callState = new DisconnectingState(ctx,this);
				break;
			default:
				Log.debug(this.getClass(), "Illegal state="+ nextState);
				return;//!!!
		}
		this.setCurrentState(callState);
	}

	private int getMakeCallTimer()
	{
		int callType = callAttr.getCallType();
		if(CallAttr.isPrivateCall(callType))
		{
			return 60;
		}
		return 60;
	}

	public void setCurrentState(ICallState currentState)
	{

		this.currentState.destory();
		this.currentState = currentState;
		int callState = currentState.getState();
		Log.debug(this.getClass(), "setCurrentState callState = " + callState);

		if(operator != null) {
			if (CallConst.CallState_WattingState != callState)
			{
				operator.ring(ctx,false);
			}
		}

		if(listener != null)
		{
			listener.updateCallState(callkey,callState,haseVideo);
		}
		else
		{
			Log.debug(this.getClass(), "setCurrentState listener = null");
		}
		launchCallActivity(callState,false);


		if(CallConst.CallState_InitState == callState)
		{
//			this.stopTimer();
			this.operator.clearResourceForCallEnd(curCallIdStr);
			setIslaunch(true);
		}
		else if(CallConst.CallState_Activite == callState)
		{
			int callType = callAttr.getCallType();
			boolean hasVideo = callAttr.isHasVideo();
			if(operator != null) {
				operator.updateAudioChannel(callType,hasVideo);
			}
			Log.debug(this.getClass(), "setCurrentState callType = " + callType);
			if(CallAttr.isPrivateCall(callType))
			{
				operator.requestAudioFocus(false);
//				operator.negotiateRtpChannel(curCallIdStr);
			}

//			if(callAttr.isSendNegotiate())
//			{
//				startTimer();
//			}
//			isRefreshVideo = true;
		}
		else if(CallConst.CallState_DisconnectingState == callState)
		{
			if(operator != null) {
				operator.updateAudioChannel(CallAttr.CallType_Prearranged,false);
			}
		}
	}

	public int doUserAction(int userAction)
	{
		Log.debug(this.getClass(),
				CallConst.stateTag(this.currentState.getState()) + " doUserAction is " + CallConst.userActionTag( userAction ));
		int result = CauseCont.OperateErr_NoAgent;
		result =  currentState.doUserAction(userAction );
		Log.debug(this.getClass(), "callAgent.doUserAction btnAction is " + userAction +  " result is " + result);
		return result;
	}

	public void receiveCallAction(int callAction)
	{
		Log.debug(this.getClass(),
				CallConst.stateTag(this.currentState.getState()) + " receiveCallAction callAction = "
						+ CallConst.sessionTag( callAction ) );

		currentState.receiveCallAction(callAction );
	}

	public void receivePCallMediaStatus(int mediaStatus)
	{
		Log.debug(this.getClass(),
				CallConst.stateTag(this.currentState.getState()) + " receivePCallMediaStatus mediaStatus = "
						+ mediaStatus);
		this.callMediaState = mediaStatus;
		if(listener != null)
		{
			listener.updateMediaStatus(callkey,mediaStatus);
		}
	}
	public void receivePCallVideoEvent()
	{
		Log.debug(this.getClass(),
				CallConst.stateTag(this.currentState.getState()) + " receivePCallVideoEvent");
		if(listener != null)
		{
			listener.updateVideoEvent(callkey);
		}
	}
	public int getState()
	{
		if(currentState != null)
		{
			return this.currentState.getState();
		}
		else
		{
			return CallConst.CallState_InitState;
		}
	}

	public boolean isActiveCall()
	{
		int callState = currentState.getState();
		if(CallConst.CallState_InitState != callState)
		{
			return true;
		}
		return false;
	}

	public List<HalfCallInfo> getCallInfoList(int callType)
	{
		List<HalfCallInfo> list = new Vector<HalfCallInfo>();
		return list;
	}

	public void updateTimer(CallTimer time) {
		this.callTime.updateTime(time);
	}

	/*public void onDisplayVideo(int callId,boolean isNew)
	{
		if(listener != null)
		{
			listener.onDisplayVideo(callId,isNew);
		}
	}*/


	@Override
	public void destory() {
		Log.debug(this.getClass(), "destory");
		if(this.operator != null)
		{
			if(this.getState() == CallConst.CallState_Activite)
			{
				this.operator.hangupCall(curCallIdStr, 486);
			}
			this.operator.clearResourceForCallEnd(curCallIdStr);
		}
		if(listener != null)
		{
			listener.updateCallState(callkey,CallConst.CallState_InitState,haseVideo);
		}
//		else
//		{
//			closeCallActivity();
//		}
//		this.stopTimer();
		/*if(localRender != null)
		{
			this.localRender.release();
			this.localRender = null;
		}
		if(remoteRender != null)
		{
			this.remoteRender.release();
			this.remoteRender = null;
		}*/

		if(currentState != null)
		{
			this.currentState.destory();
			this.currentState = null;
		}
		this.callAttr = null;
		this.callTime = null;
		this.operator.ring(ctx,false);
		this.operator = null;
		this.callkey = null;
//		this.mcIdInfo = null;
		this.curCallIdStr = null;
		this.callAttr = null;
		this.ctx = null;
	}

	public int doMakeCallAction(boolean isHaveVideo)
	{
		Context ctx = this.getCtx();
		//		boolean isVideo = false;
		//		int callType = CallAttr.CallType_Group;
		Log.debug(this.getClass(), "doMakeCallAction callAttr = " + callAttr + " isHaveVideo = " + isHaveVideo);
		if(callAttr == null)
		{
			return CauseCont.OperateErr_Exception;
		}
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			Log.debug(this.getClass(), "doMakeCallAction operator_null");
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		String callee = callAttr.getCalled().getAddrId();
		if(isHaveVideo)
		{
			callee = callAttr.getCalled().getAddrId();
		}
		int type = callAttr.getCallType();
		boolean isEmergency = callAttr.isEmergency();
		String funcNum = callAttr.getFuncName();
		String locationStr = callAttr.getLocationStr();
		Log.debug(this.getClass(), "doMakeCallAction callee = " + callee + " isHaveVideo = " + isHaveVideo + " isEmergency = " + isEmergency + " funcNum = " + funcNum);
		int result = operator.makeSingleCall(type,callee,isHaveVideo,isEmergency,funcNum,locationStr);
		if(result != CauseCont.OperateCheck_Suc)
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}

	public int doAcceptAction()
	{
		Log.debug(this.getClass(),"doAcceptAction");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		boolean hasVideo = callAttr.isHasVideo();
		int result = operator.answerCall(curCallIdStr, hasVideo);
		if(result != CauseCont.OperateCheck_Suc)
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}

	public boolean setMicrophoneEnable(boolean enable)
	{
		Log.debug(this.getClass(),"setMicrophoneEnable enable = " + enable);
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return false;
		}

		return operator.setMicrophoneEnable(curCallIdStr, enable);
	}

	public int doHangupAction(int code)
	{
		Log.debug(this.getClass(),"doHangupAction code = " + code);
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		int result = operator.hangupCall(curCallIdStr,code);
		if(result != CauseCont.OperateCheck_Suc)
		{
			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
			CommDlg.showToast(ctx,errStr);
			return result;
		}
		return CauseCont.OperateCheck_Suc;
	}

	public int doPlayWavAction()
	{
		Log.debug(this.getClass(),"doPlayWavAction");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}

		String filePath = Environment.getExternalStorageDirectory()
				+ File.separator + "CloudPTT" + File.separator  + "test.wav";
		Log.debug(this.getClass(),"doPlayWavAction filePath = " + filePath);
		operator.playWaveFile(filePath, curCallIdStr, SipManager.BITMASK_ALL);
		return CauseCont.OperateCheck_Suc;
	}

	public int doSubscribe()
	{
		Log.debug(this.getClass(),"doSubscribe");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}
		String called =  callAttr.getCalled().getAddrId();
		String uri = AddrInfo.toSipUrlFromNum(called);
		operator.sendSubscribe(uri);
		return CauseCont.OperateCheck_Suc;
	}

	public int doSwitchCamera()
	{
		Log.debug(this.getClass(),"doSwitchCamera");
		Context ctx = this.getCtx();
		CallOperator operator = this.getOperator();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateCheck_Sys_UserKeyNull;
		}
		String called =  callAttr.getCalled().getAddrId();
		String uri = AddrInfo.toSipUrlFromNum(called);
		operator.switchCamera(curCallIdStr);
		return CauseCont.OperateCheck_Suc;
	}

	public int opVideoStream(int opType)
	{
		if(currentState != null)
		{
			Log.debug(this.getClass(), CallConst.stateTag(this.currentState.getState()) + " opVideoMedia opType = " + opType);
		}
		else
		{
			Log.debug(this.getClass(), "opVideoMedia opType = " + opType);
		}
		Context ctx = this.getCtx();
		if(null == operator
				|| null == ctx)
		{
			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
			CommDlg.showToast(ctx,errStr);
			return CauseCont.OperateErr_Exception;
		}

		try
		{
			int result = operator.opVideoStream(curCallIdStr,opType);
			return result;
		}catch (Exception e)
		{
			e.printStackTrace();
			return CauseCont.OperateErr_Exception;
		}
	}

	//	private boolean micEnabled = true;
	//	public int doMicMute()
	//	{
	//		new Thread(new Runnable()
	//		{
	//			@Override
	//			public void run()
	//			{
	//				if(peerConnectionClient != null)
	//				{
	//					micEnabled = !micEnabled;
	//					peerConnectionClient.setAudioEnabled(micEnabled);
	//				}
	//			}
	//		}).start();
	//		return CauseCont.OperateCheck_Suc;
	//	}
	//
	//	public int dostartVideoSource()
	//	{
	//		new Thread(new Runnable()
	//		{
	//			@Override
	//			public void run()
	//			{
	//				if (peerConnectionClient != null)
	//				{
	//					peerConnectionClient.startVideoSource();
	//				}
	//			}
	//		}).start();
	//		return CauseCont.OperateCheck_Suc;
	//	}

	//	public int doStopVideoSource()
	//	{
	//		new Thread(new Runnable()
	//		{
	//			@Override
	//			public void run()
	//			{
	//				if (peerConnectionClient != null)
	//				{
	//					peerConnectionClient.stopVideoSource();
	//				}
	//			}
	//		}).start();
	//		return CauseCont.OperateCheck_Suc;
	//	}

	//	public void destoryCall()
	//	{
	//		Context ctx = this.getCtx();
	//		CallOperator operator = this.getOperator();
	//		if(null == operator
	//				|| null == ctx)
	//		{
	//			String errStr =  Resource.getString("operator_null");//ctx.getString(R.string.operator_null);
	//			CommDlg.showToast(ctx,errStr);
	//			return;
	//		}
	//		operator.destoryGroupCall();
	//	}

	public Context getCtx() {
		return ctx;
	}

	public CallOperator getOperator() {
		return operator;
	}

	public void clearCall()
	{
		if(clearCall != null)
		{
			clearCall.clearAllCallAgent();
		}
		//		Log.d(WebRtcCallAgent.Log_Key,"clearGroupCall");
		//		int result = operator.hangupCall(curCallId,0);
		//		if(result != CauseCont.OperateCheck_Suc) 
		//		{
		//			String errStr = CauseCont.getOperateCheckErrStr(result,ctx);
		//			CommDlg.showToast(ctx,errStr);
		//			return;
		//		}
	}

	public CallListener getListener() {
		return listener;
	}
	public void setListener(CallListener listener) {
		this.listener = listener;
		if(listener != null
			&& currentState != null)
		{
			listener.updateCallState(callkey,currentState.getState(),haseVideo);
		}
	}

	//	public void setLaucher(boolean isLaucher) {
//		Log.debug(this.getClass(), "setFloat isLaucher = " + isLaucher);
//		this.isLaucher = isLaucher;
//	}
	public void setShowFloatWin(boolean showFloatWin) {
		isShowFloatWin = showFloatWin;
	}


	private void launchCallActivity(int callState,boolean isFirst)
	{
		Log.debug(this.getClass(), "launchCallActivity isShowFloatWin = " + isShowFloatWin + " callState = " + callState);
		if(callAttr.getCallDir() == CallAttr.CallDir_MT && callState == CallConst.CallState_WattingState)
		{
			return;
		}
		if(callAttr.isAmbientListening())
		{
			return;
		}
		if(isShowFloatWin)
		{
			return;
		}
		Log.debug(this.getClass(), "launchCallActivity callState = " + callState + " isFirst = " + isFirst);
		boolean isLaunch = isLaunch(callState,isFirst);
		Log.debug(this.getClass(), "launchCallActivity isLaunch = " + isLaunch);
		if(isLaunch)
		{
			if(callAttr.isAmbientViewing())
			{
				AddrInfo info = callAttr.getCalled();
				LaunchCallInfo callInfo = callAttr.toLaunchCallInfo(false, callState, callMediaState,isLaunch);
				startFloatWindow(callInfo,info);
			}
			else
			{
				AddrInfo info = callAttr.getCalled();
				LaunchCallInfo callInfo = callAttr.toLaunchCallInfo(false, callState, callMediaState,isLaunch);
				launchCallActivity(callInfo,info);
			}
		}
	}



	private boolean isLaunch(int callState,boolean isFirst)
	{
		if(CallConst.CallState_InitState == callState
				&& isFirst)
		{
			return true;
		}
		else if(CallConst.CallState_Activite >= callState
				&& CallConst.CallState_InitState != callState)
		{
			return true;
		}
		return false;
	}
	private void launchCallActivity(LaunchCallInfo callInfo, AddrInfo fromAddressInfo)
	{
		Log.debug(this.getClass(), "launchCallActivity callInfo = " + callInfo);
		Log.debug(this.getClass(), "launchCallHandler fromAddressInfo = " + fromAddressInfo);
		if(activityCls == null)
		{
			doHangupAction(406);
			return;
		}
		Log.debug(this.getClass(), "launchCallHandler islaunch = " + islaunch);
		if(!islaunch)
		{
			return;
		}
		Intent intent = new Intent(this.ctx, activityCls);
		intent.putExtra(SipManager.EXTRA_PRIVACY_CALL_INFO, callInfo);
		intent.putExtra(SipManager.EXTRA_PRIVACY_CALL_USER, fromAddressInfo);
		intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

		this.ctx.startActivity(intent);
		//		showNotificationForCall(talkState,userInfo);
	}

	private void startFloatWindow(LaunchCallInfo callInfo, AddrInfo fromAddressInfo) {
		Log.debug(this.getClass(), "startFloatWindow");
		Intent intent = new Intent();
		intent.putExtra(SipManager.EXTRA_PRIVACY_CALL_INFO, callInfo);
		intent.putExtra(SipManager.EXTRA_PRIVACY_CALL_USER, fromAddressInfo);
		com.cloudptt.api.product.log.Log.debug(this.getClass(), "startFloatWindow callInfo.isHasVideo() = " + callInfo.isHasVideo());
		intent.setClass(ctx, floatWindowServiceCls);
		ctx.startService(intent);
	}

//	private void closeCallActivity()
//	{
//		Log.debug(this.getClass(), "closeCallActivity");
//		Intent intent = new Intent(this.ctx,cls);
//		Bundle bundle = new Bundle();
//		bundle.putString(SipManager.EXTRA_PRIVACY_CLOSE, SipManager.EXTRA_PRIVACY_CLOSE);
//		intent.putExtras(bundle);
////		intent.setAction(SipManager.EXTRA_PRIVACY_CLOSE);
////		intent.putExtra(SipManager.EXTRA_PRIVACY_CLOSE, SipManager.EXTRA_PRIVACY_CLOSE);
//		this.ctx.startActivity(intent);
//	}




	public String getCurCallIdStr() {
		return curCallIdStr;
	}

	public void updateCallDuration(int sec)
	{
		this.timeDesc = Common.getTime(sec);
		if(this.listener != null)
		{
			listener.updateCallDuration(callkey,timeDesc);
		}
	}

	public CallAttr getCallAttr() {
		return callAttr;
	}
	public String getTimeDesc() {
		return timeDesc;
	}

	public boolean isHaveActivePCall()
	{
		Log.debug(this.getClass(), "isHaveActivePCall callAttr = " + callAttr);
		int callType = callAttr.getCallType();
		if(CallAttr.isPrivateCall(callType))
		{
			return true;
		}
		return false;
	}

	public boolean isHaveActivePVoiceCall()
	{
		Log.debug(this.getClass(), "isHaveActivePVoiceCall callAttr = " + callAttr);
		if(callAttr != null
		&& !callAttr.isGroupCall()) {
			return true;
		}
		return false;
	}

	public CallInfo getCallInfo()
	{
		Log.d(GroupCallAgent.Log_Key, "getCallInfo");
		int callState = currentState.getState();
		int mediaState = this.callMediaState;
		boolean hasVideo = callAttr.isHasVideo();

		return new CallInfo(callAttr,callState,mediaState,hasVideo);
	}

//	public void startTimer() {
//		Log.debug(this.getClass(), "startTimer");
//
//		stopTimer();
////		this.operator.negotiateVideoChannel(curCallIdStr);
//		this.keepLiveTimer = new AlarmTimer(ctx,TimerOutKey_Negotiate,2,this);
//		keepLiveTimer.startRefreshTimer();
//	}
//
//	public void stopTimer() {
//		Log.debug(this.getClass(), "stopTimer");
//		if(keepLiveTimer != null)
//		{
//			this.keepLiveTimer.stopRefreshTimer();
//			this.keepLiveTimer = null;
//		}
//		isStartTimer = false;
//	}

//	@Override
//	public void timeIntervalTimeout(String alarmAction) {
//		// TODO Auto-generated method stub
//		Log.debug(this.getClass(), "timeIntervalTimeout alarmAction = " + alarmAction);
//		if(TimerOutKey_Negotiate.equals(alarmAction))
//		{
//			this.operator.negotiateVideoChannel(curCallIdStr);
//		}
//	}
	public void setHaseVideo(boolean haseVideo) {
		this.haseVideo = haseVideo;
	}
	public void screenAngle(int angle)
	{
		operator.screenAngle(curCallIdStr, angle);
	}
//	public boolean isRefreshVideo() {
//		return isRefreshVideo;
//	}
}
